;
(function() {
	var skill = {
		save: function() {
			db.update(config.dbname.busSpace, this._id, this);
		},
		destroy: function() {
			db.remove(config.dbname.busSpace, this._id);
		},
		setInfo: function(info) {
			// 描述信息
			info.name = String(info.name || "").trim();
			info.type = parseInt(info.type);
			info.type = (info.type && $Object.hasValue(BusSpaceCon.TYPE, info.type)) ? info.type : BusSpaceCon.TYPE["桌号"]; //座号、桌号、房间号、楼层
			if (!info.name) {
				throwCusError("参数错误，空间（座位、房间）名字不可为空")
			}
			/*3维信息*/
			info.x = parseFloat(info.x) || 0;
			info.y = parseFloat(info.y) || 0;
			info.z = parseFloat(info.z) || 0;
			info.length = parseFloat(info.length) || 0;
			info.width = parseFloat(info.width) || 0;
			info.height = parseFloat(info.height) || 0;
			//拓展描述
			info.intro = String(info.intro || "").trim();
			info.images = (info.images instanceof Array) ? $Array.clearNull(info.images.map(function(image_info) {
				return {
					url: image_info.url
				}
			})) : [];
			//从属关系
			var parent_space = BusSpaceCon.get(info.parent_id);
			if (!(parent_space && parent_space.bus_id === this.bus_id)) {
				info.parent_id = null;
			}
			//是否可用
			info.use_state = parseInt(info.use_state);
			info.use_state = (info.use_state && $Object.hasValue(BusSpaceCon.USE_STATE, info.use_state)) ? info.use_state : BusSpaceCon.USE_STATE["可用"];

			/*设定*/
			this.name = info.name;
			this.type = info.type;
			this.x = info.x;
			this.y = info.y;
			this.z = info.z;
			this.length = info.length;
			this.width = info.width;
			this.height = info.height;
			this.intro = info.intro;
			this.images = info.images;
			this.parent_id = info.parent_id;
			this.use_state = info.use_state;

			/*保存*/
			this.save();
		}
	}
	module.exports = skill;

	var db = require("../db/index");
	var GoodsCon = require("../goods/_con");
	var UserCon = require("../../core/user/_con");
	var BusCon = require("../../core/bus/_con");
	var AchCon = require("../ach/_con");
	var ClassifyCon = require("../bus.classify/_con");
	var TagCon = require("../bus.tag/_con");
	var LeagueCon = require("../league/_con");
	var BuffCon = require("../buff/_con");
	var BusUserBindCon = require("../bus_user_bind/_con");
	var BusGuideCon = require("../bus.guide/_con");
	var BusSpaceCon = require("../bus.space/_con");
	var CommentCon = require("../comment/_con");
	var config = require("../_include/config");
	var data_cut = require("../_include/data_cut");
	var helper = require("../_include/helper");
	var md5 = require("../_include/md5");
	var $Object = require("../_include/$.Object");
	var $Array = require("../_include/$.Array");
}());